package hangMan;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class FileRead {

	private File animals;
	private File countries;
	private File cities;
	private ArrayList<Word> animalsList;
	private ArrayList<Word> countriesList;
	private ArrayList<Word> citiesList;
	private ArrayList[] listArray = new ArrayList[3];
	boolean fileExist;

	public FileRead() {
		animals = new File("c:\\", "animal.txt");
		countries = new File("c:\\", "country.txt");
		cities = new File("c:\\", "city.txt");
		try {
			animalsList = readFromFile(animals);
			countriesList = readFromFile(countries);
			citiesList = readFromFile(cities);
			createArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public ArrayList<Word> getLists() {
		Random randomForArray = new Random();
		int intRandom = randomForArray.nextInt(listArray.length);
		return listArray[intRandom];
	}

	public ArrayList<Word> getAnimalsList() {
		return animalsList;
	}

	public ArrayList<Word> getCountriesList() {
		return countriesList;
	}

	public ArrayList<Word> getCitiesList() {
		return citiesList;
	}

	public ArrayList<Word> readFromFile(File f) throws FileNotFoundException {
		Scanner sc;
		ArrayList<Word> list = new ArrayList<Word>();
		sc = new Scanner(f);
		while (sc.hasNext()) {
			Word word = new Word(sc.next(), f.getName().split("\\.")[0]);
			
			list.add(word);
		}
		sc.close();
		return list;
	}

	public void createArray() {
		listArray[0] = animalsList;
		listArray[1] = citiesList;
		listArray[2] = countriesList;
	}
}
